using TMPro;
using UnityEngine;
using UnityEngine.UI;
using Voodoo.Pattern;

public class PrestigePanel : MonoBehaviour
{
	[SerializeField]
	private GameObject powerUps;

	[SerializeField]
	private GameObject mainPanel;

	[SerializeField]
	private GameObject congratulationsPanel;

	[SerializeField]
	private TextMeshProUGUI prestigePointsTxt;

	[SerializeField]
	private Button prestigeBtn;

	[SerializeField]
	private Button closeBtn;

	[SerializeField]
	private Button shopBtn;

	[SerializeField]
	private Button continueBtn;

	private bool mainPanelOpened;

	private int points;

	public void Setup()
	{
		SingletonMB<GameManager>.Instance.AnyWindowActive = true;
		SingletonMB<UIManager>.Instance.HideLeftBtns();
		SingletonMB<UIManager>.Instance.HideRightBtns();
		mainPanelOpened = true;
		base.gameObject.SetActive(value: true);
		mainPanel.SetActive(value: true);
		congratulationsPanel.SetActive(value: false);
		prestigeBtn.onClick.RemoveAllListeners();
		closeBtn.onClick.RemoveAllListeners();
		shopBtn.onClick.RemoveAllListeners();
		continueBtn.onClick.RemoveAllListeners();
		prestigeBtn.onClick.AddListener(Prestige);
		closeBtn.onClick.AddListener(Close);
		points = 0;
		int num = SingletonMB<GameManager>.Instance.Money + SingletonMB<GameManager>.Instance.MoneySpent;
		if (num > 1000)
		{
			points = Mathf.FloorToInt(num / 1000);
		}
		prestigeBtn.interactable = points > 0;
		prestigePointsTxt.text = points.ToString();
		powerUps.SetActive(value: false);
	}

	private void Close()
	{
		SingletonMB<UIManager>.Instance.ShowLeftBtns();
		SingletonMB<UIManager>.Instance.ShowRightBtns();
		SingletonMB<GameManager>.Instance.AnyWindowActive = false;
		base.gameObject.SetActive(value: false);
		powerUps.SetActive(value: true);
	}

	private void Prestige()
	{
		Debug.LogError("Prestige");
		if (points > 0)
		{
			mainPanelOpened = false;
			SingletonMB<GameManager>.Instance.Prestige(points);
			mainPanel.SetActive(value: false);
			congratulationsPanel.SetActive(value: true);
			shopBtn.onClick.AddListener(delegate
			{
				Close();
				SingletonMB<UIManager>.Instance.upgradesBtn.onClick.Invoke();
			});
			continueBtn.onClick.AddListener(Close);
		}
	}

	private void Update()
	{
		if (mainPanelOpened)
		{
			if (Singleton<InputController>.Instance.X)
			{
				Prestige();
			}
			if (Singleton<InputController>.Instance.Back)
			{
				Close();
			}
			return;
		}
		if (Singleton<InputController>.Instance.X)
		{
			Close();
			SingletonMB<UIManager>.Instance.upgradesBtn.onClick.Invoke();
		}
		if (Singleton<InputController>.Instance.Back)
		{
			Close();
		}
	}
}
